Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring VariantContextComparator #1629

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

lbergelson
Copy link
Member

@clintval I might have gone a bit overboard on refactoring. I really hate how normal comparators are written and like to rewrite them as the newer Comparator.comparing() chains so I did that.

It's great that you added tests, I ended up condensing them into a single test case with a dataprovider and a few additional use cases. I never would have bothered having any if you hadn't mad them in the first place though!

* Responding to my own pr comments on #1593
* doing some refactoring to use the Comparator.comparing API
* adding a few more tests
@lbergelson
Copy link
Member Author

@cmnbroad Could you take a look at this, it ended up being more new code than I meant it to be so it probably needs a second pair of eyes.

@lbergelson
Copy link
Member Author

blocked because of #1637

private final Comparator<VariantContext> internalComparator;

private static Comparator<VariantContext> makeComparator(final Map<String, Integer> contigIndexLookup) {
return Comparator.comparingInt((VariantContext vc) -> contigIndexLookup.get(vc.getContig()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are using a lambda to determine the index given the contig names perhaps that is what you should compose in the constructors:

If the constructor param is a SAMSeqDict then (x) -> dict.getRecord(x).getIndex().
If the constructor param is a List then you create that Map.

Also you can add here the NPE capture into a IAE (or whatever) for missing contigs.

private static class SortedUniquedElementsComparator<T extends Comparable<T>> implements Comparator<Collection<T>>{
@Override
public int compare(final Collection<T> o1, final Collection<T> o2) {
final Iterator<T> left = new TreeSet<>(o1).iterator();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps is worth to add trivial cases to avoid TreeSet constructons since quite often alt-alleles list are just 1 in length?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants